<?php 
function send_mail(){
	$url = 'http://sendcloud.sohu.com/webapi/mail.send_template.json';
	$vars = json_encode(array(
		'to'=>array('1217867491@qq.com'),
		'sub'=>array(
			'code'=>array('123456')
			)
		)
	);
	$API_USER = 'mengzhuweilai_test_tQVbD4';//用户名登录(http://sendcloud.sohu.com)登录获取
	$API_KEY = 'ZETPbaJsXY7gBPEd';//一般企业开通了服务会给你一个唯一的key作为识别
	$param = array(
		'api_user' => $API_USER,//使用api_user和api_key进行验证
		'api_key' => $API_KEY,
		'from' => 'm18748342258@163.com',//发信人,用正确邮件地址替代
		'fromname' => 'SendCloud',
		'substitution_vars' => $vars,
		'template_invoke_name' => 'test_template',//模板名称
		'subject' => '欢迎来到德莱联盟世界!',
		'resp_email_id' => 'true'
		);

	$data = http_build_query($param);

	$options = array(
		'http' => array(
			'method' => 'POST',
			'header' => 'Content-Type:application/x-www-form-urlencoded',
			'content' => $data
		));
	$context = stream_context_create($options);
	$result = file_get_contents($url,FILE_TEXT,$context);

	return $result;
} 

echo send_mail();

